package cn.bupt.adt.util;

public class AccountUtil {

	private static char[] chrs = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
			'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
			};
	private static char[] nums = {'0','1','2','3','4','5','6','7','8','9'};
	/**
	 * 随机生成n位的账号，由字母数字下划线组成，首字母非数字
	 * @param len
	 * @return
	 */
	public static String getRandomAccount(int len){
		if(len == 0)
			return "";
		StringBuilder sb = new StringBuilder();
		sb.append(chrs[(int)(Math.random() * chrs.length)]);
		for(int i = 1;i<len;i++) {
			sb.append(nums[(int)(Math.random() * nums.length)]);
		}
		return sb.toString();
	}
	public static String getRandomInvitaCode(int len){
		if(len == 0)
			return "";
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i<len;i++) {
			sb.append(nums[(int)(Math.random() * nums.length)]);
		}
		return sb.toString();
	}
	public static void main(String[] args) {
/*		StringBuilder sb = new StringBuilder();
		for(int i = 0;i<26;i++) {
			sb.append("'"+(char)('a'+i)+"'");
			sb.append(',');
		}
		System.out.println(sb.substring(0, sb.length()-1));
		sb.delete(0, sb.length());
		for(int i = 0;i<26;i++) {
			sb.append("'"+(char)('A'+i)+"'");
			sb.append(',');
		}
		System.out.println(sb.substring(0, sb.length()-1));
		for(int i = 0;i<10;i++) {
			System.out.print("'"+i+"'");
			System.out.print(',');
		}*/
		System.out.println(getRandomInvitaCode(6));
	}
}
